package com.dly.blog.queue;

import com.dly.blog.service.FileService;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.redisson.api.RBlockingDeque;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;

/**
 * @Author: DaiLiYu
 * @Date: 2023/7/14 16:44
 */
@Component
@Slf4j
@AllArgsConstructor
public class QueueRunner implements CommandLineRunner {

    private final RBlockingDeque<String> fileBlockingFairQueue;

    private final FileService fileService;

    @Override
    public void run(String... args) throws Exception {
        new Thread(() -> {
            log.info("文件 的 死信队列 开启中...");
            while (true) {
                String orderNo;
                try {
                    orderNo = fileBlockingFairQueue.take();
                } catch (Exception e) {
                    continue;
                }
                log.info("file Id {} 已经失效", orderNo);
                fileService.reviseFile(orderNo);
            }
        }).start();
    }
}
